package com.tedu.T2;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");

        Channel c=f.newConnection().createChannel();
        //      声明一个消息队列helloworld
        /*
         * @param
         * 1.队列名
         * 2.是否是持久队列
         * 3.是否是排他（独占）队列
         * 4.是否自动删除（自动判断，没有消费者就删除）
         * 5.队列其它属性*/
        /*@Param 1.交换机
         * */
        c.queueDeclare("task_queue",true,false,false,null);
        while (true){
            System.out.println("enter:");
            String s=new Scanner(System.in).nextLine();
            c.basicPublish("", "task_queue", MessageProperties.PERSISTENT_TEXT_PLAIN, s.getBytes());
            c.close();
        }
    }
}
